package com.example.bigevent.service;

import com.example.bigevent.mapper.GameMapper;
import com.example.bigevent.pojo.Game;
import com.example.bigevent.pojo.Review;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class GameService {
    @Autowired
    private GameMapper gameMapper;

    public void add(Game game) {
        game.setPrice(new BigDecimal("0.0"));
        gameMapper.insert(game);
    }

    public List<Game> listAll() {
        return gameMapper.selectAll();
    }

    public Game findById(Integer id) {
        return gameMapper.selectById(id);
    }

    public List<Review> findReviewsByGameId(Integer id) {
        return gameMapper.selectReviewsByGameId(id);
    }

    public void addReview(Integer id, Review review) {
        gameMapper.insertReview(id, review);
    }

    public void purchase(Integer id) {
        gameMapper.purchase(id);
    }
}